/**
 * iria garcia fernandez (iria.garcia.fernandez@usi.ch)
 */

package ch.usi.inf.pf2.gui;

import org.jfree.chart.JFreeChart; 
import org.jfree.chart.ChartUtilities; 
import org.jfree.chart.ChartFactory; 
import org.jfree.chart.plot.PlotOrientation;

import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;


import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

public class Waveform{	
	
	public static void drawWaveform(ArrayList<Integer> values) {
		// Create a simple XY chart 
		XYSeries series = new XYSeries("Waveform"); 
		
		for(int i=0;i<values.size();i++)
		{
			int intValue = values.get(i);
			
			series.add(i,intValue);
			series.add(i+0.9999999,intValue);
			
		}
	
		
		// Add the series to your data set 
		XYSeriesCollection dataset = new XYSeriesCollection(); 
		dataset.addSeries(series);
		
		// Generate the graph 
		JFreeChart chart = ChartFactory.createXYLineChart(
		"Waveform", // Title 
		"Time", // x-axis Label 
		"Value", // y-axis Label 
		dataset, // Dataset 
		PlotOrientation.VERTICAL, // Plot Orientation 
		true,// Show Legend 
		true, // Use tooltips 
		false // Configure chart to generate URLs? 
		);
					
		try { 
			ChartUtilities.saveChartAsJPEG(new File("chart.jpg"), chart, 500, 300);
		} catch (IOException e) { 
			System.err.println("Problem occurred creating chart.");
		}
		
		
		WaveFormFrame i = new WaveFormFrame();
			
		i.startFrame();
						
	}
	
	
}
